﻿package com.badibadi.activity;

import com.badibadi.fragment.ClubApplicationFormFragment0;
import com.badibadi.mytools.TabHostUtils;
import com.badibadi.uniclubber.R;

import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

//Utils.showMessage
public class ClubApplicationFormActivity extends BaseActivity {

	private TabHost mTabHost;
	private Bundle bun;
	private String showType = null, cid = null, c_name = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.club_application_form);
		try {
			showType = getIntent().getStringExtra("showType");// user个人，club俱乐部
			cid = getIntent().getStringExtra("cid");// 俱乐部id
			c_name = getIntent().getStringExtra("c_name");// 俱乐部名字
		} catch (Exception e) {
			// TODO: handle exception
		}
		this.findViewById(R.id.club_applicateion_form_imageView1)
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						ClubApplicationFormActivity.this.finish();
					}
				});
		this.findViewById(R.id.club_applicateion_form_before_index)
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(
								ClubApplicationFormActivity.this,
								IndexActivity.class);
						startActivity(intent);
					}
				});
		settingTabHost();
		InitFragment("0");
	}

	private void InitFragment(String temp_edit) {
		// TODO Auto-generated method stub
		ViewFragmentHolder holder = new ViewFragmentHolder();
		ClubApplicationFormFragment0 fragment0 = new ClubApplicationFormFragment0();
		bun = new Bundle();
		bun.putString("editcontent", temp_edit);
		bun.putString("showType", showType);
		bun.putString("cid", cid);
		if (showType != null && showType.equals("club")) {
			bun.putString("c_name", c_name);
		}
		fragment0.setArguments(bun);
		holder.transaction.replace(R.id.club_application_layout, fragment0);
		holder.transaction.commit();
	}

	private void settingTabHost() {
		// TODO Auto-generated method stub
		mTabHost = (TabHost) this
				.findViewById(R.id.club_application_form_tabhost);
		mTabHost.setup();
		mTabHost.addTab(mTabHost
				.newTabSpec("application_form one")
				.setIndicator(
						getResources().getString(R.string.ToBeDetermined),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab1));
		mTabHost.addTab(mTabHost
				.newTabSpec("application_form two")
				.setIndicator(getResources().getString(R.string.Agreement),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab2));
		mTabHost.addTab(mTabHost
				.newTabSpec("application_form three")
				.setIndicator(getResources().getString(R.string.Disagree),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab3));
		TabHostUtils.SetTabHost(this, mTabHost);
		mTabHost.setOnTabChangedListener(new OnTabChangeListener() {

			@Override
			public void onTabChanged(String arg0) {
				switch (mTabHost.getCurrentTab()) {
				case 0:
					InitFragment("0");
					break;
				case 1:
					InitFragment("1");
					break;
				case 2:
					InitFragment("2");
					break;
				default:
					break;
				}
			}
		});
	}

}
